package util;

import model.altarica_fields.Var;

public class BinaryTree {

	
	private BinaryTree left;
	private BinaryTree right;
	
	private Object value;
	
	
	public BinaryTree(Object value) {
		
		this.value = value;
		
		this.left = null;
		this.right = null;
	}
	
	public BinaryTree() {
		
		this.value = null;
		
		this.left = null;
		this.right = null;
	}
	
	public void setValue(Object value) {
		
		this.value = value;
	}
	
	public Object getValue() {
		
		return this.value;
	}
	
	public boolean isLeaf() {
		
		return (left == null && right == null);
	}
	
	public void addLeft(BinaryTree left) {
		
		this.left = left;
	}
	
	public void addRight(BinaryTree right) {
		
		this.right = right;
	}
	
	public BinaryTree getLeft() {
		
		return this.left;
	}
	
	public BinaryTree getRight() {
		
		return this.right;
	}
	
	public void copy(BinaryTree t) {
		
		this.value = t.value;
		this.left = t.left;
		this.right = t.right;
	}
	
	public String toString() {
		
		String str = new String();

		if (left != null)
			str += left.toString() + " ";
		
		if (value instanceof Var)
			str += ((Var) value).getId();
		else
			str += value;

		if (right != null)
			str += " " + right.toString();
		return str;
	}
}
